using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Acms.AcmsControls
{
    [ToolboxData("<{0}:FlashContentControlDisplay runat=server></{0}:FlashContentControlDisplay>")]
    public class FlashContentControlDisplay : BaseContentControlDisplay<FlashContentControlProperties>
    {
        private Acms.WebControls.FlashControl _FlashControl;
        public Acms.WebControls.FlashControl FlashControl
        {
            get
            {
                EnsureChildControls();
                return _FlashControl;
            }
        }

        protected override void CreateChildControls()
        {
            this.Controls.Clear();
            _FlashControl = new Acms.WebControls.FlashControl();
            this.Controls.Add(_FlashControl);
            base.CreateChildControls();
        }

        protected override void DataBindChildren()
        {
            if (Properties != null && Properties.HasResource())
            {
                FlashControl.FlashFileUrl = string.Format("~/File.aspx?id={0}", Properties.ResourceId);
                if (Properties.Width == 0 || (MaxWidth > 0 && Properties.Width > MaxWidth))
                {
                    FlashControl.Width = MaxWidth;
                }
                else
                {
                    FlashControl.Width = Properties.Width;
                }
                if (Properties.Height == 0 || (MaxHeight > 0 && Properties.Height > MaxHeight))
                {
                    FlashControl.Height = MaxHeight;
                }
                else
                {
                    FlashControl.Height = Properties.Height;
                }
                FlashControl.MinVersion = Properties.MinVersion;
                FlashControl.WMode = this.WMode;
            }
        }

        public override void RenderBeginTag(HtmlTextWriter writer)
        {
            
        }

        public override void RenderEndTag(HtmlTextWriter writer)
        {
        }

        private int maxWidth;
        public int MaxWidth
        {
            get { return maxWidth; }
            set { maxWidth = value; }
        }

        private int maxHeight;
        public int MaxHeight
        {
            get { return maxHeight; }
            set { maxHeight = value; }
        }

        private Acms.WebControls.FlashControl.WModes wMode;
        public Acms.WebControls.FlashControl.WModes WMode
        {
            get { return wMode; }
            set { wMode = value; }
        }
	
        public Dictionary<string, string> Variables
        {
            get { EnsureChildControls(); return FlashControl.Variables; }
        }

        public bool AllowFullScreen
        {
            get 
            {
                EnsureChildControls();
                return FlashControl.AllowFullScreen; 
            }
            set
            {
                EnsureChildControls();
                FlashControl.AllowFullScreen = value;
            }
        }

        public override bool IsEmpty
        {
            get 
            {
                return Properties == null || !Properties.HasResource();
            }
        }

    }
}
